package com.deductive.service.special.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deductive.domain.special.SpatialShip;
import com.deductive.service.special.SpatialShipService;
import com.deductive.mapper.special.SpatialShipMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 47338
* @description 针对表【spatial_ship】的数据库操作Service实现
* @createDate 2025-09-08 15:06:41
*/
@Service
public class SpatialShipServiceImpl extends ServiceImpl<SpatialShipMapper, SpatialShip>
    implements SpatialShipService{

    @Override
    public List<Tree<Object>> listTree() {
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        treeNodeConfig.setIdKey("id");
        treeNodeConfig.setNameKey("name");
        treeNodeConfig.setParentIdKey("parentId");
        List<SpatialShip> list = this.list();
        List<Tree<Object>> treeList = TreeUtil.build(list, 0, treeNodeConfig, (specialHospital, tree) -> {
            tree.setId(specialHospital.getId()); // 设置节点ID
            tree.setName(specialHospital.getName()); // 设置节点名称（显示文本）
            tree.setParentId(specialHospital.getParentId());
            tree.putExtra("type", specialHospital.getType());
            tree.putExtra("preparationLevel", specialHospital.getPreparationLevel());
            tree.putExtra("fullLoadDisplacement", specialHospital.getFullLoadDisplacement());
            tree.putExtra("shipLength", specialHospital.getShipLength());
            tree.putExtra("shipWidth", specialHospital.getShipWidth());
            tree.putExtra("waterDepth", specialHospital.getWaterDepth());
            tree.putExtra("speed", specialHospital.getSpeed());
            tree.putExtra("endurance", specialHospital.getEndurance());
            tree.putExtra("operationalRadius", specialHospital.getOperationalRadius());
            tree.putExtra("otherData", specialHospital.getOtherData());
        });
        return treeList;
    }
}




